// 被控制的窗口

const { BrowserWindow } = require("electron");

const path = require("path");

let controlWindow;
exports.createControlWindow = () => {
  controlWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: false,
      sandbox: false, // 为了解决preload通过 require 引入自己的js文件报错问题
      contextIsolation: false,
      enableRemoteModule: true,
      preload: path.resolve(__dirname, "../scripts/preload.js"),
    },
  });
  controlWindow.loadFile(
    path.resolve(__dirname, "../../renderer/pages/control/index.html")
  );

  controlWindow.openDevTools();
};

// mainWindow 窗口，接收渲染进程 控制端 发送的消息
exports.send = (channel, ...args) => {
  controlWindow.webContents.send(channel, ...args);
};
